import { ElMessageBox } from "element-plus";
import { h } from "vue";

const showSeatDetails = (seatData) => {
  console.log(seatData);

  let rootStyle = {
    cursor: "pointer",
    userSelect: "none",
  };

  let lineStyle = {
    width: "100%",
    display: "flex",
    justifyContent: "space-between",
    // alignItems: "center",
    padding: "5px",
    borderBottom: "1px solid #8888",
  };

  let labelStyle = {
    minWidth: "6em",
    fontWeight: "bold",
  };

  let lines = [
    h("p", { style: lineStyle }, [
      h("b", { style: labelStyle }, "席位名称"),
      h("span", null, seatData.seatName),
    ]),
    h("p", { style: lineStyle }, [
      h("b", { style: labelStyle }, "所属单位"),
      h("span", null, seatData.seatDepartment),
    ]),
    h("p", { style: lineStyle }, [
      h("b", { style: labelStyle }, "逻辑扇区"),
      h("span", null, seatData.logicSectorCode),
    ]),
    h("p", { style: lineStyle }, [
      h("b", { style: labelStyle }, "物理扇区"),
      h("span", null, seatData.sectorCodes.join(", ")),
    ]),
    h("p", { style: lineStyle }, [
      h("b", { style: labelStyle }, "人员信息"),
      h("span", null, seatData.users.length + "人"),
    ]),
  ];

  for (let i = 0; i < seatData.users.length; i++) {
    lines.push(
      h("p", { style: lineStyle }, [
        h(
          "b",
          null,
          seatData.users[i].name
            ? seatData.users[i].name
            : seatData.users[i].userName
        ),
        h(
          "span",
          null,
          seatData.users[i].code
            ? seatData.users[i].code
            : seatData.users[i].userId
        ),
        h(
          "span",
          null,
          seatData.users[i].level
            ? seatData.users[i].level
            : seatData.users[i].controlLevel
        ),
        h(
          "span",
          null,
          seatData.users[i].post
            ? seatData.users[i].post
            : seatData.users[i].seatPost
        ),
        h(
          "span",
          null,
          seatData.users[i].qualification +
            " / " +
            (seatData.users[i].role
              ? seatData.users[i].role
              : seatData.users[i].seatRole)
        ),
        // h("span", null, ),
      ])
    );
  }

  ElMessageBox({
    // title: seatData.seatName + "（" + seatData.seatDepartment + "）",
    title: "席位详情",
    message: h("div", { style: rootStyle }, lines),
    draggable: true,
  });
};

export default showSeatDetails;

/*
{
  "seatName": "TWR_EAST",
  "seatDepartment": "塔台管制室(双流)",
  "seatType": "普通管制",
  "seatPostList": [
    "管制岗",
    "协调岗",
    "第三岗"
  ],
  "logicSectorCode": "ETWR",
  "sectorCodes": [
    "ETWR"
  ],
  "users": [
    {
      "code": "20180023",
      "name": "闫雨豪",
      "post": "协调岗",
      "role": "管制",
      "level": "四级",
      "qualification": "全放单"
    }
  ],
  "frequency": 130.35,
  "defaultFrequency": 0,
  "colorDark": "#FF1493",
  "colorLight": "#CCCCCC",
  "relatedGates": null,
  "borderOn": 0,
  "lastUpdate": "2023-09-11 03:40:21"
}
*/

/**
 {
    "seatName": "TM01",
    "seatType": "普通管制",
    "seatPostList": [
        "管制岗",
        "协调岗",
        "第三岗"
    ],
    "logicSectorCode": "TM01",
    "sectorCodes": [
        "AP01",
        "AP02",
        "AP03",
        "AP04",
        "AP06",
        "AP11",
        "AP12",
        "AP13",
        "AP14",
        "AP18",
        "AP1A",
        "AP5H",
        "AP5L",
        "AP7C",
        "AP81",
        "AP9C",
        "APA1",
        "APC7",
        "APC9"
    ],
    "users": [
        {
            "userId": 20200027,
            "seatPost": "协调岗",
            "seatRole": "管制",
            "userName": "路勇",
            "startTime": "2023-09-11 03:02:37",
            "seatPostId": 2,
            "seatRoleId": 2,
            "controlLevel": "五级",
            "qualification": "部分放单",
            "controlLevelId": 5,
            "qualificationId": 2
        },
        {
            "userId": 20180056,
            "seatPost": "管制岗",
            "seatRole": "管制",
            "userName": "李皓瑞",
            "startTime": "2023-09-11 03:09:13",
            "seatPostId": 1,
            "seatRoleId": 2,
            "controlLevel": "五级",
            "qualification": "全放单",
            "controlLevelId": 5,
            "qualificationId": 1
        }
    ],
    "frequency": 124.85,
    "color": "#0000FF",
    "defaultColor": "#32CD32",
    "planningSectorCodes": null,
    "planningFrequency": null
}
 */
